from wxPython.wx import *

ID_ABOUT=101
ID_EXIT=110
ID_BUTTON1=110

class MainWindow(wxFrame):

    def __init__(self, parent, id, title):
        wxFrame.__init__(self, parent, -1, title, size=(400, 400),
                         style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
        self.CreateStatusBar() # A Statusbar in the bottom of the window
        # Setting up the menu.
        filemenu = wxMenu()
        filemenu.Append(ID_ABOUT, "&About", "Information about this program")
        filemenu.AppendSeparator()
        filemenu.Append(ID_EXIT,"&Exit", "Terminate the program")
        # Creating the menubar.
        menuBar = wxMenuBar()
        menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the MenuBar
        self.SetMenuBar(menuBar)  # Adding the MenuBar to the Frame content.
        EVT_MENU(self, ID_ABOUT, self.OnAbout)
        EVT_MENU(self, ID_EXIT, self.OnExit)

        # A multiline TextCtrl - This is here to show how the events
        # work in this program, don't pay too much attention to it
        self.logger = wxTextCtrl(self, 5, "", wxPoint(100, 20),
                                 wxSize(100, 100),
                                 wxTE_MULTILINE | wxTE_READONLY)

        self.vsizer = wxBoxSizer(wxVERTICAL)
        self.sizer = wxGridSizer(rows=8, cols=8)

        self.vsizer.Add(self.sizer, 0, wxEXPAND)
        self.vsizer.Add(self.logger, 1, wxEXPAND)

        self.SetSizer(self.vsizer)
        self.SetAutoLayout(1)
        self.vsizer.Fit(self)

        self.Show(true)

    def get_move(self, game, state):
        board = state.board
        self.display(board)


    def display(self, board):
        self.buttons = {}
        for i in range(1, 9):
            for j in range(1, 9):
                pos = i*10+j
                id = ID_BUTTON1 + pos
                button = wxButton(self, id, "Button &"+`pos`)
                EVT_BUTTON(self, id, self.OnClick)
                self.buttons[(i, j)] = button
                self.sizer.Add(button, 1, wxEXPAND)




    def OnClick(self, e):
        self.logger.AppendText(str(vars(e)))

    def OnAbout(self, e):
        # Create a message dialog box
        msg = "A simple checkers game frontend in wxPython."
        d = wxMessageDialog(self, msg, style=wxOK)
        d.ShowModal()
        d.Destroy()

    def OnExit(self, e):
        self.Close(True)

app = wxPySimpleApp()
frame = MainWindow(None, -1, "Sample editor")
app.MainLoop()
